using System;
using System.Collections.Generic;
using System.Text;
using QLPMT_DTO;
using QLPMT_DAO;
namespace QLPMT_BUS
{
   public class ThuocBUS
    {
       public List<Thuoc> GetAll()
       {
           return new ThuocDAO().GetAll();
       }
       public string MaBenhThuocMoi()
       {
           List<Thuoc> list = new List<Thuoc>();
           list = this.GetAll();
           Thuoc temp = new Thuoc();
           foreach (Thuoc X in list)
           {
               temp.Mathuoc = X.Mathuoc;
           }
           string ma = "";
           if (temp.Mathuoc != null)
           {
               char[] chuoi = temp.Mathuoc.ToCharArray(2, temp.Mathuoc.Length - 2);
               string chuoima = "";
               foreach (char charX in chuoi)
               {
                   chuoima = chuoima + charX;
               }
               int sobenhnhan = int.Parse(chuoima) + 1;
               ma = "MT" + sobenhnhan.ToString();
           }
           else
               ma = "MT1";
           return ma;
       }
       //Them Thuoc
       public Boolean InsertThuoc(string ma, string ten)
       {
           try
           {
         
           
                   Thuoc dto = new Thuoc(ma, ten);
                   new ThuocDAO().ThemThuocMoi(dto);
               
           }
           catch
           {
               return false;
           }
           return true;
       }
       public void UpDateThuoc(string ma, string ten)
       {
           Thuoc dto = new Thuoc(ma, ten);
           ThuocDAO dao = new ThuocDAO();
           dao.suaThuoc(dto);
       }
       
     
    }
}
